""" 学习itertools.accumulate
    bisect.bisect.left """

import bisect
import random
from typing import List
import itertools

class Solution:

    def __init__(self, w: List[int]):
        self.pre = list(itertools.accumulate(w))
        self.total = sum(w)

    def pickIndex(self) -> int:
        x = random.randint(1, self.total)
        return bisect.bisect_left(self.pre, x)
    
x = Solution([1,2,3,6,7])
x.pickIndex()
print(x.pickIndex())